function [s_ret, r, eoe] = doAction(mdp, s,a)
% s es una permutación de [1:9]

%     P = perms(1:9);
    
%     [~,index] = ismember(P, s,'rows');
 
%     initial_state_index = find(index, 1);  
%     initial_state = P(initial_state_index,:);
    
    empty_square_pos = find(s==9);
    
    r = 0;
    eoe = false;
    s_next = calculate_puzzle_board(s);
    
    if a ==1
        if empty_square_pos > 3
            s_next = swap(s, empty_square_pos, empty_square_pos-3);
        end
    elseif a==2
        if mod(empty_square_pos,3)~=0
            s_next = swap(s, empty_square_pos, empty_square_pos+1);
        end
    elseif a==3
        if empty_square_pos < 7
            s_next = swap(s, empty_square_pos, empty_square_pos+3);
        end
    elseif a==4
        if mod(empty_square_pos,3)~=1
            s_next = swap(s, empty_square_pos, empty_square_pos-1);
        end
    end
    
    if(isequal(s_next, 1:9))
        eoe = true;
        r = 10;
        disp(r);
    end
    
    s_ret = calculate_puzzle_number(s_next); 
end
